package com.atguigui.leetcode;

import java.util.HashSet;
import java.util.Set;

/**
 * 961.在长度 2N 的数组中找出重复 N 次的元素
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by  wangjiaxin  on 2022/5/21 23:01
 */
public class P961NRepeatedElementInSize2nArray {
    public static void main(String[] args) {
        Solution solution = new P961NRepeatedElementInSize2nArray().new Solution();
        // TO TEST
    }

    //leetcode submit region begin(Prohibit modification and deletion)

    /**
     *
     */
    class Solution {
        public int repeatedNTimes(int[] nums) {
            Set<Integer> set = new HashSet<>();

            for (int num : nums) {
                if (set.contains(num)) {
                    return num;
                } else {
                    set.add(num);
                }
            }
            return -1;
        }
    }
}
